from django.shortcuts import render, HttpResponse
from django_redis import get_redis_connection
from community.forms.account import RegisterModelForm, SendSmsForm
from django.http import JsonResponse

"""
用户账户相关功能：注册 短信 登录 注销
"""


def send_sms(request):
    """发送短信"""
    # 校验手机号：格式正确 非空
    form = SendSmsForm(request, data=request.GET)  # 实例化SendSmsForm, 执行__init__方法
    if form.is_valid():
        return JsonResponse({'status': True})
    return JsonResponse({'status': False, 'error': form.errors})


def register(request):
    """注册"""
    if request.method == 'GET':
        form = RegisterModelForm()
        return render(request, 'community/register.html', {'form': form})
    # POST
    return JsonResponse({})
